/**
 * Created by Administrator on 2016/2/28.
 */

    function animateTop(obj,target){
        clearInterval(obj.timer1)
        obj.timer1=setInterval(function(){
            var leader=obj.offsetTop;
            //var target=-bbsLiHeight;
            var step=(target-leader)/10;
            step=step>0?Math.ceil(step):Math.floor(step);
            if(leader!=target){
                obj.style.top=leader+step+"px"
            }else{
                clearInterval(obj.timer1);
            }
        },50);
    };

    function animate(obj,target){
        clearInterval(obj.timer);
        obj.timer=setInterval(function(){
            var leader=obj.offsetLeft;
            var step=(target-leader)/10;
            step=step>0?Math.ceil(step):Math.floor(step);
            if(leader!=target){
                obj.style.left=leader+step+"px"
            }else{
                clearInterval(obj.timer);
            }
        },25);
    }

function aniMate(obj, json, fn) {
    clearInterval(obj.timer);
    obj.timer = setInterval(function () {
        var flag = true;
        for (var k in json) {
            if (k == "opacity") {
                var leader = getStyle(obj, k) * 100;
                var target = json[k] * 100;
                var step = (target - leader) / 20;
                step = step > 0 ? Math.ceil(step) : Math.floor(step);
                obj.style[k] = (leader + step) / 100;
            } else if (k == "zIndex") {
                obj.style[k] = json[k];
            } else {
                var leader = parseInt(getStyle(obj, k)) || 0;
                var target = json[k];
                var step = (target - leader) / 10;
                step = step > 0 ? Math.ceil(step) : Math.floor(step);
                obj.style[k] = leader + step + "px";
            }
            if (leader != target) {
                flag = false;
            }
        }
        if (flag) {
            clearInterval(obj.timer);
            if (fn) {
                fn();
            }
        }
    }, 25)
}

function getStyle(obj, attr) {
    if (obj.currentStyle) {
        return obj.currentStyle[attr];
    } else {
        return window.getComputedStyle(obj, null)[attr];
    }
}
